#include "HighScore.h"

HighScore::HighScore()
{
		
	high_score_read = ifstream("HighScore.txt");	

	if ( !high_score_read)
	{
		throw "The High Score File Can Not Be Opened";
	}
	else
	{
		load();
		high_score_read.close();
	}
}

int HighScore::get()
{
	return _high_score;
}

void HighScore::load()
{
	string line; 

	getline(high_score_read, line, '\n');
	_high_score =  atoi(line.c_str());
}


int HighScore::update(int new_score)
{
	
	if(new_score > _high_score)
	{
		_high_score = new_score;

		char score_str [10];
		itoa(new_score, score_str, 10);

		high_score_write.open("HighScore.txt");
		high_score_write <<std::string(score_str)<<endl;
		high_score_write.close();
	}
	return _high_score;
}